import { fileURLToPath, URL } from "node:url";
import Components from "unplugin-vue-components/vite";
import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    Components({
      resolvers: [AntDesignVueResolver({ importStyle: "less", resolveIcons: true })],
      dirs: ["./src/views", "./src/components"],
      dts: true,
    })
  ],
  css: {
    preprocessorOptions: {
      less: {
        additionalData: '@import "./src/assets/variable";',
        javascriptEnabled: true,
        modifyVars: {
          "primary-color": "#1890ff", // 全局主色
          "link-color": "#1890ff", // 链接色
          "success-color": "#52c41a", // 成功色
          "warning-color": "#faad14", // 警告色
          "error-color": "#f5222d", // 错误色
          "font-size-base": "14px", // 主字号
          "heading-color": "#2c3e50", // 标题色
          "text-color": "rgba(0, 0, 0, 0.65)", // 主文本色
          "text-color-secondary": "rgba(0, 0, 0, 0.65)", // 次文本色
          "disabled-color": "rgba(0, 0, 0, 0.25)", // 失效色
          "border-radius-base": "2px", // 组件/浮层圆角
          "border-color-base": "#d9d9d9", // 边框色
          "box-shadow-base": "0 2px 8px rgba(0, 0, 0, 0.15)" // 浮层阴影
        }
      }
    }
  },
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  server: {
    port: 8700,
    host: true,

    proxy: {
      "^/admin": {
        target: "http://localhost:8702",
        changeOrigin: true
      },
      "^/upload": {
        target: "http://localhost:8704",
        rewrite(path) {
          return "http://localhost:8704" + path.replace("upload", "");
        },
        changeOrigin: true
      }
    }
  },
  preview: {
    port: 8705,
    host: true,
    proxy: {
      "^/admin": {
        target: "http://localhost:8702",
        changeOrigin: true
      },
      "^/upload": {
        target: "http://localhost:8704",
        rewrite(path) {
          return "http://localhost:8704" + path.replace("upload", "");
        },
        changeOrigin: true
      }
    }
  }
});
